package com.lishe.lishe.lishe.module.myorder.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.lishe.lishe.R;
import com.lishe.lishe.lishe.base.BaseActivity;
import com.lishe.lishe.lishe.module.myorder.adapter.SelectCouponAdapter;
import com.lishe.lishe.lishe.module.shopingcart.bean.CouponBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Bin
 * 选择优惠券使用
 */
public class SelectCouponActivity extends BaseActivity implements View.OnClickListener {

    private RecyclerView mRecyclerView;
    private List<CouponBean> mCouponList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_selectcouponlist);
        mCouponList = (List<CouponBean>) getIntent().getSerializableExtra("CouponList");
        initView();
    }

    private void initView() {
        TextView title = findViewById(R.id.title_text_title);
        title.setText(getString(R.string.use_coupon));
        findViewById(R.id.title_left_button).setOnClickListener(this);
        findViewById(R.id.nouse).setOnClickListener(this);

        mCouponList = (ArrayList<CouponBean>) getIntent().getSerializableExtra("CouponList");
        mRecyclerView = findViewById(R.id.recyclerview);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        SelectCouponAdapter adapter = new SelectCouponAdapter(this, mCouponList, new SelectCouponAdapter.ItemClicker() {
            @Override
            public void onItemClick(int position) {
                Intent intent = new Intent();
                intent.putExtra("position", position);
                SelectCouponActivity.this.setResult(2, intent);
                finish();
            }
        });
        mRecyclerView.setAdapter(adapter);

        if (mCouponList.size() == 0) {
            //无数据展示
            findViewById(R.id.none_layout).setVisibility(View.VISIBLE);
        } else {
            //有数据展示
            findViewById(R.id.content_layout).setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.title_left_button:
                finish();
                break;
            case R.id.nouse:
                this.setResult(1);
                finish();
                break;
        }
    }

}
